package cn.iocoder.yudao.module.ao.service.classlocation;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.ao.controller.admin.classlocation.vo.*;
import cn.iocoder.yudao.module.ao.dal.dataobject.classlocation.ClassLocationDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ao.dal.mysql.classlocation.ClassLocationMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.ao.enums.ErrorCodeConstants.*;

/**
 * 上课场地信息 Service 实现类
 *
 * @author 禾安
 */
@Service
@Validated
public class ClassLocationServiceImpl implements ClassLocationService {

    @Resource
    private ClassLocationMapper classLocationMapper;

    @Override
    public Long createClassLocation(ClassLocationSaveReqVO createReqVO) {
        // 插入
        ClassLocationDO classLocation = BeanUtils.toBean(createReqVO, ClassLocationDO.class);
        classLocationMapper.insert(classLocation);

        // 返回
        return classLocation.getLocationId();
    }

    @Override
    public void updateClassLocation(ClassLocationSaveReqVO updateReqVO) {
        // 校验存在
        validateClassLocationExists(updateReqVO.getLocationId());
        // 更新
        ClassLocationDO updateObj = BeanUtils.toBean(updateReqVO, ClassLocationDO.class);
        classLocationMapper.updateById(updateObj);
    }

    @Override
    public void deleteClassLocation(Long id) {
        // 校验存在
        validateClassLocationExists(id);
        // 删除
        classLocationMapper.deleteById(id);
    }

    @Override
        public void deleteClassLocationListByIds(List<Long> ids) {
        // 删除
        classLocationMapper.deleteByIds(ids);
        }


    private void validateClassLocationExists(Long id) {
        if (classLocationMapper.selectById(id) == null) {
            throw exception(LOCATION_NOT_EXISTS);
        }
    }

    @Override
    public ClassLocationDO getClassLocation(Long id) {
        return classLocationMapper.selectById(id);
    }

    @Override
    public PageResult<ClassLocationDO> getClassLocationPage(ClassLocationPageReqVO pageReqVO) {
        return classLocationMapper.selectPage(pageReqVO);
    }

}